package neuronvisualizer;
import java.awt.Color;
import java.util.ArrayList;

import com.threed.jpct.Primitives;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.Object3D;
	/*
	 *Section.java
	 *@author Charles Schuh
	 *
	 * Represents a group of neurons in the same column and layer.
	 * From a distance, a section will be rendered as a single model, indicating
	 * the presence of neurons.  As the camera gets closer to the section, the
	 * entire network will be rendered.
	 */
public class Section {
	private ArrayList<Integer> sectionNeurons; //IDs of neurons that belong to this section
	private Driver parent;//list of neurons in the ENTIRE simulation
	private SimpleVector midpoint; //The center of the section, used to place the low LoD model
	private Object3D model;
	private Object3D glow;
	private int col, lay; //The column/layer this section represents
	private int objID; //stores the model's ID
	
	public Section(Driver p, SimpleVector mid, int c, int l){
		col = c;
		lay = l;
		parent = p;
		sectionNeurons = new ArrayList<Integer>();
		midpoint = mid;
		model = Primitives.getPyramide(100f*parent.getScale());
		model.setTexture("dblue");
		model.setEnvmapped(Object3D.ENVMAP_ENABLED);
		model.translate(midpoint);
		model.setSelectable(true);
		objID = model.getID();
		createGlow();
	}
	
	public ArrayList<Integer> getNeurons(){
		return sectionNeurons;
	}

	public void unspark(){
		glow.setVisibility(false);
	}
	public void spark(){
		glow.setVisibility(true);
	}
	public void createGlow(){
	    glow = Primitives.getPlane(5,80f);
        glow.setCulling(false);
        glow.setBillboarding(Object3D.BILLBOARDING_ENABLED);
        glow.setTexture("glow");
    	glow.translate(model.getTransformedCenter());
    	glow.setTransparency(0);
    	glow.setTransparencyMode(Object3D.TRANSPARENCY_MODE_ADD);
    	
    	glow.setLighting( Object3D.LIGHTING_NO_LIGHTS);
    	glow.setAdditionalColor( new Color( 255,255,255) );
    	
    	glow.build();
    	glow.setVisibility(false);
    }
	
	public void addNeuron(Neuron n){
		sectionNeurons.add(n.getID());
	}
	public SimpleVector getMidpoint(){
		return midpoint;
	}
	public void hideSection(){
		for(Integer i:sectionNeurons){
			parent.hideNeuron(i);
		}
		model.setVisibility(Object3D.OBJ_VISIBLE);
	}
		
	public void showSection(){
		for(Integer i:sectionNeurons){
			parent.showNeuron(i);
		}
		model.setVisibility(Object3D.OBJ_INVISIBLE);
	}
	
	public Object3D getModel(){
		return model;
	}
	public Object3D getGlow(){
		return glow;
	}
	public int getObjectID(){
		return objID;
	}
	public boolean isHidden(){
		//Returns true if the section is in low LoD(hidden) mode
		//False if the full network is showing
		return model.getVisibility();
	}
	
	public int getCol(){
		return col;
	}
	public int getLay(){
		return lay;
	}
	public String toString(){
		String str = "Col: "+col +" Lay: "+lay;
		return str;
	}
	public void destroyModel(){
		model = null;
	}
}
